package com.teziyou.commodity.service;

import java.util.List;

import javax.annotation.Resource;

import org.apache.thrift.TException;
import org.springframework.stereotype.Service;

import com.mytravel.platform.bean.AdministrativeBean;
import com.mytravel.platform.service.AdministrativeService;
import com.teziyou.commodity.core.thrift.ConnectionManager;

@Service
public class AreaService {
	
	@Resource(name="areaConnectionManager")
	private ConnectionManager connectionManager;
	
	private AdministrativeService.Client client;
	
	public String addAndUpdateDivision(int id, int parentDivisionID,
			String name, String capitalCityName, double GPSLat, double GPSLng,
			int itemValue){
		try {
			return client.addAndUpdateDivision(id, parentDivisionID, name, capitalCityName,
					GPSLat, GPSLng, itemValue);
		} catch (TException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}

	public AdministrativeBean getAdministrativeById(int divisionID) {
		try {
			return client.getAdministrativeById(divisionID);
		} catch (TException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}

	public List<AdministrativeBean> getAdministrativeListByLevel(
			int parentDivisionID, int itemLevel, int itemValue){
		try {
			return client.getAdministrativeListByLevel(parentDivisionID, itemLevel,
					itemValue);
		} catch (TException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}

	public List<AdministrativeBean> getAdministrativeListByPid(
			int parentDivisionID, int itemValue){
		try {
			return client.getAdministrativeListByPid(parentDivisionID, itemValue);
		} catch (TException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}

	public String queryAllForPid(int parentDivisionID, int itemValue){
		try {
			return client.queryAllForPid(parentDivisionID, itemValue);
		} catch (TException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}

	public String queryByItemLevel(int parentDivisionID, int itemLevel,
			int itemValue){
		try {
			return client.queryByItemLevel(parentDivisionID, itemLevel, itemValue);
		} catch (TException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}

	public String queryOneForDivision(int divisionID, int itemValue){
		try {
			return client.queryOneForDivision(divisionID, itemValue);
		} catch (TException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}

	public String queryOneForDivisionByName(String name, int itemValue){
		try {
			return client.queryOneForDivisionByName(name, itemValue);
		} catch (TException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}

	public String queryTree(int parentDivisionID, int itemValue){
		try {
			return client.queryTree(parentDivisionID, itemValue);
		} catch (TException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}

}
